'''
主机特征的类
提取函数和过程在Main函数中
这里主要是定义类，看起来更规范

一个Pcap文件中包含的主机信息定义为如下：
包含流的数量
各流中数据包的数量 均值 方差 最大值 最小值
流的持续时间最大值 最小值 均值 方差
'''

class HostFeatureExtractor:
    def __init__(self, pcap_file):
        self.pcap_filename = pcap_file
        
        self.flow_counts = 0
        self.packets_counts_mean = 0
        self.packets_counts_std = 0
        self.packets_counts_max = 0
        self.packets_counts_min = 0
        
        self.flow_duration_max = 0
        self.flow_duration_min = 0
        self.flow_duration_mean = 0
        self.flow_duration_std = 0
        
    def __str__(self) -> str:
        return f"Pcap file:" + str(self.pcap_filename) + "\n" + \
               f"Packets counts:" + str(self.flow_counts) + "\n" + \
               f"Packets counts mean:" + str(self.packets_counts_mean) + "\n" + \
               f"Packets counts std:" + str(self.packets_counts_std) + "\n" + \
               f"Packets counts max:" + str(self.packets_counts_max) + "\n" + \
               f"Packets counts min:" + str(self.packets_counts_min) + "\n" + \
               f"Flow duration max:" + str(self.flow_duration_max) + "\n" + \
               f"Flow duration min:" + str(self.flow_duration_min) + "\n" + \
               f"Flow duration mean:" + str(self.flow_duration_mean) + "\n" + \
               f"Flow duration std:" + str(self.flow_duration_std) + "\n"
            
    def Return_Features(self):
        # 返回特征值列表
        return [self.flow_counts, self.packets_counts_mean, self.packets_counts_std, self.packets_counts_max, self.packets_counts_min, self.flow_duration_max, self.flow_duration_min, self.flow_duration_mean, self.flow_duration_std]